<?php 
require_once(ABSPATH. 'include/model/Category.php');
require_once(ABSPATH. 'include/dao/CategoryDAO.php');

class CategoryControl {
	public $model;
	public $method="Post";
	
	function  __construct(){
		$method = $_SERVER['REQUEST_METHOD'];
		if($method!="GET"){
			if($_POST["c_method"]=="PUT")
				$method = "PUT";
		}				
		switch($method){
			case "GET":
				$this->get();
				break;
			case "POST":
				$this->post();
				break;
			case "PUT":
				$this->put();
				break;
			default:
				break; //?
		}
	}
	
	function get(){
		$id = $_GET['id'];
		if($id){
			$dao = new categoriesDAO();
			$this-> model = $dao->get($id);
			$this -> method="PUT";
		}else{
			$this-> model = new Category();
		}
	}
	
	function post(){
		$c = new Category();
		$c-> id = $_POST["id"];
		$c-> name = $_POST["name"];
		$c-> screen_name = $_POST["screen_name"];
		$c-> notes = $_POST["notes"];
		$c-> list_order = $_POST["list_order"];	

		$dao = new categoriesDAO();
		$dao-> insert($c);
		
		$this-> model = $c;
	}
	
	function put(){
		$c = new Category();
		$c-> id = $_POST["id"];
		$c-> name = $_POST["name"];
		$c-> screen_name = $_POST["screen_name"];
		$c-> notes = $_POST["notes"];
		$c-> list_order = $_POST["list_order"];	

		$dao = new categoriesDAO();
		$dao-> update($c);
		
		$this-> model = $c;	
	}
	
	function delete(){
		
	}

}

?>